package com.ivy.wechat;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private ImageButton ib_weixin;
    private ImageButton ib_contact;
    private ImageButton ib_find;
    private ImageButton ib_me;

    private WeixinFragment weixinFragment;
    private ContactFragment contactFragment;
    private FindFragment findFragment;
    private MeFragment meFragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ib_weixin = (ImageButton) findViewById(R.id.ib_weixin);
        ib_contact = (ImageButton) findViewById(R.id.ib_contect);
        ib_find = (ImageButton) findViewById(R.id.ib_find);
        ib_me = (ImageButton) findViewById(R.id.ib_me);

        ib_weixin.setOnClickListener(this);
        ib_contact.setOnClickListener(this);
        ib_find.setOnClickListener(this);
        ib_me.setOnClickListener(this);

        //  启动点击页面
        ib_weixin.performClick();
    }


    @Override
    public void onClick(View v) {
        //  先清除图标
        clearIcon();
        FragmentManager manager = getFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();

        switch (v.getId()){
            case R.id.ib_weixin:
                if(weixinFragment == null){
                   weixinFragment = new WeixinFragment();
                }
                transaction.replace(R.id.fragment_container,weixinFragment);
                //ib_weixin.setImageResource(R.drawable.               );
                break;
            case R.id.ib_contect:
                if(contactFragment == null){
                    contactFragment = new ContactFragment();
                }
                transaction.replace(R.id.fragment_container,contactFragment);
                break;
            case R.id.ib_find:
                if(findFragment == null){
                    findFragment = new FindFragment();
                }
                transaction.replace(R.id.fragment_container,findFragment);
                break;
            case R.id.ib_me:
                if(meFragment == null){
                    meFragment = new MeFragment();
                }
                transaction.replace(R.id.fragment_container,meFragment);
                break;
        }
        transaction.commit();
    }
    private void clearIcon() {
        //ib_weixin.setImageResource(R.drawable.     );

        // ib_contact  ib_find   ib_me
    }
}
